package com.basic.boot.web.service;

import com.basic.boot.web.dao.UserMapper;
import com.basic.boot.web.dto.UserDTO;
import com.basic.boot.web.model.User;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author cherrish
 * @time 2019-03-18 10:34
 * @name UserService
 * @desc:
 */
@Service
public class UserService {
    @Resource
    UserMapper userMapper;

    public List<User> list(){
        return userMapper.selectByExample(null);
    }

    public User add(UserDTO dto){
        User user = dto.convert2User();
        int r = userMapper.insert(dto.convert2User());
        user.setId(r);
        return user;
    }

    private User convertFor(UserDTO dto){
        User user = new User();
        BeanUtils.copyProperties(dto, user);
        return user;
    }
}
